package com.zego.wawaji.ui.coupon.panel.invalid;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;

import com.zego.wawaji.R;
import com.zego.wawaji.ui.base.BasePanel;
import com.zego.wawaji.ui.base.CustomRecyclerView;
import com.zego.wawaji.ui.base.xlistview.ExListView;
import com.zego.wawaji.ui.coupon.bean.Coupon;

import java.util.ArrayList;
import java.util.List;

/**
 * 已失效
 * Created by Su on 2018/2/9.
 */
public class CouponInvalidPanel extends BasePanel implements View.OnClickListener {
    private CustomRecyclerView statusLayout;
    private ExListView exListView;

    private InvalidAdapter adapter;
    private List<Coupon> list = new ArrayList<>();

    public CouponInvalidPanel(Context context, List<Coupon> list) {
        super(context);
        setContentView(R.layout.coupon_invalid);
        this.list = list;
        initView();
    }

    private void initView() {
        statusLayout = (CustomRecyclerView) findViewById(R.id.statusLayout);
        View mViewTop = LayoutInflater.from(getContext()).inflate(R.layout.layout_margintop, null);
        exListView = statusLayout.getExListView();
        exListView.setPullRefreshEnable(true);
        exListView.setPullLoadEnable(true);
        exListView.addHeaderView(mViewTop);
        adapter = new InvalidAdapter(getContext(), list);
        exListView.setAdapter(adapter);
        refreshView();
    }

    public void refresh(List<Coupon> data) {
        this.list = data;
        refreshView();
    }

    private void refreshView() {
        if (list == null) {
            statusLayout.showNetError();
            return;
        }

        if (list.size() <= 0) {
            statusLayout.showNoData("您还没有已失效优惠券");
            return;
        }

        adapter.notifyDataSetChanged();
        statusLayout.showExListView();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        }
    }
}